home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Night Owl 6
/
Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso
/
031a
/
winbang.zip
/
BANG.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-12-03
|
14KB
|
482 lines
/* ----- BANG.C -------------------------------------------------------------
*
* DESCRIPTION:
*
* Sample Program for Destroying WinDoom errors
* (that means everything)
*
* REMARKS:
* Needed files are only the resource file PENG.RES.
* Compilation without explicit .DEF file.
*
* CHANGES:
*
* V0.1 09-11-91 Heiner Eichmann
* & Michael Schuschk
* Desperate start of programming.
*
* V0.2 10-11-91 Heiner Eichmann
* & Jürgen Christ
* Cleaned up program code and brought to first time
* functioning (a real strong performance for a
* pascal programmer). Shooting within and without the
* window is possible.
*
* V0.25 12-11-91 Michael Schuschk
* Fixed bug with crippled shots appearing when window
* is iconized and resized again. Screen is saved at
* program start and will be restored before ending the
* program.
*
* V0.3 22-11-91 Heiner Eichmann
* There's only an ABOUT dialog box and the sound
* missing. All other things are the way we wanted
* them.
*
* V0.35 24-11-91 Michael Schuschk
* ABOUT box with informations about this ultimate
* program added. Window size at first start is
* now depending on the width of the text lines
* appearing within the window.
*
* V0.4 25-11-91 Heiner Eichmann
* Only slight corrections. Translation of text and
* comments into english language. Now only the sound
* is missing.
*
* V0.5 26-11-91 Michael Schuschk
* Slight corrections on the ABOUT box and shooting
* hole design. And new in this version: the first
* appearance of sound! But until now it sounds only
* like a gun with sound absorber. This "pop" will
* possibly be caused by the StartSound() and
* StopSound() functions.
* V0.6 27-11-91 Jürgen Christ & Heiner Eichmann
* New cursor created. The word WinDoom was discovered
* (Many thanks to Holger Eichmann). A small problem
* with the distribution of the painted holes around
* the cross-hair if fixed. The About About... window
* was created. Problems with the aboutbitmap.
* V1.0 03-12-91 Heiner Eichmann
* Problems with the aboutabout-resource ignored. Light
* changes of the sound-commands. Version number changed
* to 1.0!!!!! Install and document created. Program
* is now ready to mail.
*
*
* INCLUDES:
*/
#include <windows.h>
#include <stdlib.h>
/*
* DEFINES:
*/
#define STARTPOSX CW_USEDEFAULT
#define STARTPOSY CW_USEDEFAULT
#define RANGEXDIV 20
#define RANGEYDIV 20
#define FIREDELAY 30
#define HALF_SIZE 8 /* Size of icon LOCH div 2 */
#define IDM_SYSABOUT 4242
#define ID_OK 101
#define ABOUTABOUT 6942
/*
* EXTERNAL:
*/
/*
* TYPES:
*/
/*
* VARIABLES:
*/
HCURSOR hcursor, gaehn_cursor;
HANDLE scheiss_c;
HDC hdcvar, hdcmem, hdcold;
HBITMAP hbitm, sbitm;
POINT ptSize, ptOrg;
BITMAP bm;
short cxSize, cySize;
int rangex, rangey;
int load_flag, treffer_flag;
int iMaxZeile; /* Maximum width of text in pixel */
short cxChar, cxCaps, cyCaps; /* Dimensions of one char of actual
system font */
#define LINENUMS 8
char acText[LINENUMS][100] = {
"Death to Mickeysoft: The program",
"everyone was waiting for",
"",
"Left mousebutton: Fire !",
"",
"Right mousebutton: Back to work.",
"",
"Written by REMBRANDT, POWER MIKE und McJOSH."};
/*
* PROTOTYPES
*/
int PASCAL WinMain (HANDLE, HANDLE, LPSTR, int);
long FAR PASCAL _export WindowProcedure (HWND, unsigned, WORD, LONG);
BOOL FAR PASCAL AboutBox(HWND, unsigned, WORD, LONG);
/*
* RETURN:
*
* CALL AND PARAMETERS:
*/
/*
*
* ------------------------------------------------------------------------ */
/* ----- WinMain ----------------------------------------------------------
*
* Windows Entry Function
* ---------------------------------------------------------------------- */
int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
HANDLE hInstance; /* Actual instance */
HANDLE hPrevInstance; /* Preious instance */
LPSTR lpszCmdLine; /* Command line parameter */
int nCmdShow; /* Window or icon? */
{
HWND hWindow; /* Window handle */
HMENU hSysMenu; /* System menu handle */
MSG Message; /* Message struct */
WNDCLASS WindowClass; /* Window class */
TEXTMETRIC tm; /* Text dimensions */
HDC hdcSystemDC; /* Screen display context */
static char acName[] = "hallo"; /* Window name */
int i; /* Counter, what else? */
/* Already an application of the same type running? */
scheiss_c = hInstance;
load_flag = -1;
treffer_flag = 0;
if (!hPrevInstance) {
WindowClass.style = CS_VREDRAW | CS_HREDRAW;
WindowClass.lpfnWndProc = WindowProcedure;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hInstance = hInstance;
WindowClass.hIcon = LoadIcon (hInstance, (LPSTR) "MegaIcon");
WindowClass.hCursor = LoadCursor (hInstance, (LPSTR) "GAEHN");
WindowClass.hbrBackground = GetStockObject (WHITE_BRUSH);
WindowClass.lpszMenuName = NULL;
WindowClass.lpszClassName = acName;
/* Already existing a window of the same class? */
if (!RegisterClass (&WindowClass))
return (FALSE);
}
/* Get dimensions of an capital char of the actual system font */
hdcSystemDC = CreateDC("DISPLAY", NULL, NULL, NULL);
GetTextMetrics(hdcSystemDC, &tm);
cxChar = tm.tmAveCharWidth;
cxCaps = (tm.tmPitchAndFamily & 1 ? 3 : 2) * cxChar / 2;
cyCaps = tm.tmHeight + tm.tmExternalLeading;
/* Get maximum with of one text row in pixels */
iMaxZeile = 0;
for (i = 0; i < LINENUMS; i++)
iMaxZeile = max(iMaxZeile, LOWORD(GetTextExtent(hdcSystemDC,
acText[i], strlen(acText[i]))));
DeleteDC(hdcSystemDC);
/* Create window */
hWindow = CreateWindow (acName, /* Window class name */
"Death to Mickeysoft", /* Window title */
WS_OVERLAPPED /* Window style */
|WS_CAPTION|WS_SYSMENU
|WS_MINIMIZEBOX,
STARTPOSX, /* Window start */
STARTPOSY, /* position and */
iMaxZeile + 10, /* size */
cyCaps * (LINENUMS + 2),
NULL,
NULL,
hInstance,
NULL);
/* Append menu entry for About... function */
hSysMenu = GetSystemMenu(hWindow, FALSE);
AppendMenu(hSysMenu, MF_SEPARATOR, 0, NULL);
AppendMenu(hSysMenu, MF_STRING, IDM_SYSABOUT, "About Bang...");
AppendMenu(hSysMenu, MF_STRING, ABOUTABOUT, "About About...");
/* Show Window */
ShowWindow (hWindow, SW_SHOWMINIMIZED);
UpdateWindow (hWindow);
hcursor = LoadCursor(hInstance, "MegaCursor");
gaehn_cursor = LoadCursor(hInstance, "GAEHN");
sbitm = LoadBitmap(hInstance, "LOCH");
/* Setup sound queue */
OpenSound();
SetSoundNoise(S_WHITE2048, 5);
SetVoiceQueueSize(1, 1000);
SetVoiceAccent(1, 200, 30, S_NORMAL, 40);
/* message loop */
while (GetMessage (&Message, NULL, 0, 0) ){
TranslateMessage (&Message);
DispatchMessage (&Message);
}
return (Message.wParam);
} /* this was win main ... */
/* ----- BallerBumm -----------------------------------------------------
*
* Do the great bang one time
* ---------------------------------------------------------------------- */
void krawumm()
{
int posx, posy;
int i;
POINT ptcursorpos;
GetCursorPos((LPPOINT)&ptcursorpos);
posx = ptcursorpos.x - rangex / 2 - HALF_SIZE;
posy = ptcursorpos.y - rangey / 2 - HALF_SIZE;
treffer_flag = -1;
/* Display shooting hole */
BitBlt(hdcvar, posx+random(rangex), posy+random(rangex), ptSize.x,
ptSize.y, hdcold, ptOrg.x, ptOrg.y, SRCAND);
/* And make the appropriate noise */
SetVoiceSound(1, (long)(500) << 16, 1);
StartSound();/* MessageBeep(0);*/
}
/* ---------------------------------------------------------------------- */
long FAR PASCAL _export DummyProcedure (hWnd, uiMessage, wParam, lParam)
HWND hWnd; /* Window handle */
unsigned uiMessage; /* Message number */
WORD wParam; /* wParam and lParam contain */
LONG lParam; /* additional informations */
{
return (DefWindowProc (hWnd, uiMessage, wParam, lParam));
}
/* The following procedure is obviously necessary to update the whole screen.
At the moment there is no other method known to me. */
void restorescreen()
{
HWND dummy;
WNDCLASS WindowClass; /* Window class */
WindowClass.style = CS_VREDRAW | CS_HREDRAW;
WindowClass.lpfnWndProc = DummyProcedure;
WindowClass.cbClsExtra = 0;
WindowClass.cbWndExtra = 0;
WindowClass.hInstance = scheiss_c;
WindowClass.hIcon = NULL;
WindowClass.hCursor = NULL;
WindowClass.hbrBackground = GetStockObject (WHITE_BRUSH);
WindowClass.lpszMenuName = NULL;
WindowClass.lpszClassName = "rembrandt";
/* Already a window of the same class existing? */
RegisterClass (&WindowClass);
if (treffer_flag)
{
dummy = CreateWindow ("rembrandt",
"Death to Mickeysoft",
WS_OVERLAPPED,
0,
0,
cxSize,
cySize,
NULL,
NULL,
scheiss_c,
NULL);
ShowWindow(dummy, SW_SHOWMAXIMIZED);
InvalidateRgn(dummy,NULL, TRUE);
DestroyWindow(dummy);
treffer_flag = 0;
}
}
long FAR PASCAL _export WindowProcedure (hWnd, uiMessage, wParam, lParam)
HWND hWnd; /* Window handle */
unsigned uiMessage; /* Message number */
WORD wParam; /* wParam and lParam contain */
LONG lParam; /* additional informations */
{
HDC hDisplayContext; /* Display context handle
for window function */
PAINTSTRUCT PaintStructure; /* Info for window
repainting */
int i;
static int ballerbumm = 0;
static int cxClientArea, cyClientArea;
/* Width and height of
client area */
static int cyOffset; /* Vertical offset for text
display */
FARPROC lpAboutProc; /* Pointer to the About
dialog box function */
switch (uiMessage){
case WM_CREATE :
/* Get screen dimensions */
cxSize = GetSystemMetrics(SM_CXSCREEN);
cySize = GetSystemMetrics(SM_CYSCREEN);
/* Back to where the action is... */
return(0);
case WM_SIZE :
/* Get client area width and height for centered
text display */
cxClientArea = LOWORD(lParam);
cyClientArea = HIWORD(lParam);
if (wParam == SIZENORMAL) {
SetCursor(hcursor);
SetCapture(hWnd);
ballerbumm = 1;
hdcvar = CreateDC("DISPLAY", NULL, NULL, NULL);
hdcmem = CreateCompatibleDC(hdcvar);
cxSize = GetSystemMetrics(SM_CXSCREEN);
rangex = cxSize / RANGEXDIV;
cySize = GetSystemMetrics(SM_CYSCREEN);
rangey = cySize / RANGEYDIV;
hbitm = CreateCompatibleBitmap(hdcvar,
cxSize, cySize);
SelectObject(hdcmem, hbitm);
hdcold = CreateCompatibleDC(hdcvar);
SelectObject(hdcold, sbitm);
SetMapMode(hdcold, GetMapMode(hdcvar));
GetObject(sbitm, sizeof(BITMAP), (LPSTR) &bm);
ptSize.x = bm.bmWidth;
ptSize.y = bm.bmHeight;
DPtoLP(hdcvar, &ptSize, 1);
ptOrg.x = 0;
ptOrg.y = 0;
DPtoLP (hdcmem, &ptOrg, 1);
}
if (wParam == SIZEICONIC) {
/* And now delete the bunch of device
contexts, because there are only 6 of
them system wide */
if (load_flag)
load_flag = 0;
else
{
DeleteDC(hdcvar);
DeleteDC(hdcmem);
DeleteDC(hdcold);
restorescreen();
}
}
break;
case WM_PAINT :
hDisplayContext = BeginPaint (hWnd, &PaintStructure);
/* Get vertical offset for text display */
cyOffset = max(0, cyClientArea - (LINENUMS * cyCaps));
/* Display text centered in window */
for (i = 0; i < LINENUMS; i++){
SetTextAlign(hDisplayContext, TA_CENTER | TA_TOP);
TextOut (hDisplayContext, cxClientArea / 2,
cyOffset+(i * cyCaps), acText[i],
(int)strlen(acText[i]));
SetTextAlign(hDisplayContext, TA_LEFT | TA_TOP);
}
EndPaint (hWnd, &PaintStructure);
break;
case WM_LBUTTONUP :
StopSound();
KillTimer(hWnd, 1);
return(0);
case WM_TIMER :
krawumm();
return(0);
case WM_LBUTTONDOWN :
if (ballerbumm) {
krawumm();
SetTimer(hWnd, 1, FIREDELAY, NULL);
return(0);
}
break;
case WM_RBUTTONDOWN :
if (ballerbumm) {
ballerbumm = 0;
StopSound();
ReleaseCapture();
SetCursor(gaehn_cursor);
return(0);
}
break;
case WM_SYSCOMMAND:
if (wParam == IDM_SYSABOUT){
lpAboutProc = MakeProcInstance(AboutBox, scheiss_c);
DialogBox(scheiss_c, "MEGAABOUT", hWnd, lpAboutProc);
FreeProcInstance(lpAboutProc);
}
if (wParam == ABOUTABOUT){
lpAboutProc = MakeProcInstance(AboutBox, scheiss_c);
DialogBox(scheiss_c, "ABOUTABOUT", hWnd, lpAboutProc);
FreeProcInstance(lpAboutProc);
}
break;
case WM_DESTROY :
DeleteDC(hdcvar);
DeleteDC(hdcmem);
DeleteDC(hdcold);
CloseSound();
restorescreen();
PostQuitMessage (0);
/* Back to where the action is... */
return(0);
}
if (ballerbumm)
return(0);
else
return (DefWindowProc (hWnd, uiMessage, wParam, lParam));
} /* this was the window function */
/* ----- AboutBox -------------------------------------------------------
*
* About box function
* ---------------------------------------------------------------------- */
BOOL FAR PASCAL AboutBox(hDialog, uiMeldung, wParam, lParam)
HWND hDialog; /* Dialog box handle */
unsigned uiMeldung; /* Dialog box message */
WORD wParam; /* wParam und lParam contain */
LONG lParam; /* additional informations */
{
switch (uiMeldung){
/* Dialog box initialized: only default actions */
case WM_INITDIALOG:
return(TRUE);
/* User likes to keep on firing */
case WM_COMMAND:
if (wParam == ID_OK){
EndDialog(hDialog, TRUE);
return(TRUE);
}
break;
}
return(FALSE);
}